package com.drools.drools.chapter3;

import com.drools.drools.BaseTest;
import com.drools.drools.model.Car;
import com.drools.drools.model.Person;
import org.junit.Test;
import org.kie.api.runtime.KieSession;

/**
 * Created with IntelliJ IDEA.
 * User: mishuai
 * Date: 2019-04-25
 * Time: 00:26
 * Des:
 */
public class Drools7ApiTest extends BaseTest{

    @Test
    public void testDrools7Api(){
        /*KieServices kieServices=KieServices.get();

        KieContainer kieContainer=kieServices.getKieClasspathContainer();

        KieSession kieSession=kieContainer.newKieSession("all-rules");*/

        KieSession kieSession=super.getKieSession("test-drools7");



        Person p1=new Person();
        p1.setAge(30);
        Car c1=new Car();
        c1.setPerson(p1);

        Person p2=new Person();
        p2.setAge(70);
        Car c2=new Car();
        c2.setPerson(p2);

        kieSession.insert(c1);
        kieSession.insert(c2);

        int count=kieSession.fireAllRules();
        kieSession.dispose();

        System.out.println("Fire " + count + " rule(s)!");
        System.out.println("The new discount is " + c1.getDiscount() + "%");
        System.out.println("The new discount is " + c2.getDiscount() + "%");


    }
}
